include(cc_library)
include(cc_binary)
include(cc_test)

cc_library(
  NAME 
    runtime
  HDRS
    options.h
    forward_params.h
    dit_forward_params.h
    params_utils.h
    executor.h
    executor_impl.h
    base_executor_impl.h
    dit_executor.h
    $<$<BOOL:${USE_NPU}>:acl_graph_executor_impl.h>
    worker.h
    worker_impl.h
    llm_worker_impl.h
    vlm_worker_impl.h
    dit_worker.h
    embed_worker_impl.h
    embed_vlm_worker_impl.h
    engine.h
    llm_engine.h
    vlm_engine.h
    dit_engine.h
    worker_client.h
    xservice_client.h
    speculative_engine.h
    speculative_worker_impl.h
  SRCS
    executor.cpp
    base_executor_impl.cpp
    dit_executor.cpp
    $<$<BOOL:${USE_NPU}>:acl_graph_executor_impl.cpp>
    worker.cpp
    worker_impl.cpp
    llm_worker_impl.cpp
    vlm_worker_impl.cpp
    dit_worker.cpp
    embed_worker_impl.cpp
    embed_vlm_worker_impl.cpp
    llm_engine.cpp
    vlm_engine.cpp
    dit_engine.cpp
    worker_client.cpp
    xservice_client.cpp
    params_utils.cpp
    speculative_engine.cpp
    speculative_worker_impl.cpp
  DEPS
    torch
    $<$<BOOL:${USE_NPU}>:torch_npu>
    :common
    :model_context
    :request
    :state_dict
    :dit_cache
    $<$<BOOL:${USE_NPU}>:npu_layers>
    :model
    :models
    :sampler
    :tokenizer
    :model_loader
    :util
    :worker_service
    :xllm_server
    $<$<BOOL:${USE_NPU}>:xllm_ops>
    :eplb
    glog::glog
    Folly::folly
    absl::strings
    absl::synchronization
    absl::flat_hash_map
    proto::xllm_proto
    $<$<BOOL:${USE_MLU}>:torch_mlu>
)

cc_library(
  NAME 
    master
  HDRS
    llm_master.h
    master.h
    vlm_master.h
    dit_master.h
  SRCS
    llm_master.cpp
    master.cpp
    vlm_master.cpp
    dit_master.cpp
  DEPS
    :common
    :distributed_runtime
    :scheduler
    :request
    :runtime
    :model
    :models
    $<$<BOOL:${USE_NPU}>:npu_layers>
    :chat_template
    glog::glog
    $<$<BOOL:${USE_MLU}>:torch_mlu>
)

if(USE_NPU)
cc_test(
  NAME
    acl_graph_executor_test
  SRCS
    acl_graph_executor_test.cpp
  DEPS
    :runtime
    :model_loader
    :batch
    :block
    :model
    :models
    :sampler
    :kv_cache
    GTest::gtest_main
    torch_npu
)
target_link_libraries(acl_graph_executor_test
                      PRIVATE
                      torch_npu
                      ascendcl
                      hccl
                      c_sec
                      nnopbase
                      )
# Use --whole-archive for spdlog to ensure all symbols are available for xllm_kernels
# This resolves the undefined reference issues in xllm_kernels
target_link_options(acl_graph_executor_test PRIVATE 
  "-Wl,--whole-archive" 
  "${CMAKE_BINARY_DIR}/third_party/spdlog/libspdlog.a"
  "-Wl,--no-whole-archive")
endif()
